package com.mdxl.util;

import java.util.Date;
import java.util.Map;

import static com.alibaba.druid.util.Utils.md5;

/**
 * Created by blackangel on 2016/12/22.
 */
public class CommonUtils {
    public static String getString(Map<String, Object> map, String key) {
        if (map != null && map.containsKey(key)) {
            if (map.get(key) != null) {
                return map.get(key).toString();
            }
        }
        return null;
    }

    public static Integer getInt(Map<String, Object> map, String key) {
        if (map != null && map.containsKey(key)) {
            return Integer.parseInt(map.get(key).toString());
        }
        return null;
    }

    //生成简单token
    public static String generateToken(String userid, String siteid, int d) {
        String commenKey = "123";
        Date c_date = new Date();
        String date = DateUtils.formatDate(DateUtils.addDays(c_date, d), "yyyy-MM-dd");
        String userToken = md5(userid + commenKey + date);
        return userToken;
    }
}
